package com.example.community.dao;

import com.example.community.mapper.PaymanagerMapper;
import com.example.community.mapper.PaytypeMapper;
import com.example.community.mapper.RepairMapper;
import com.example.community.mapper.UsersMapper;
import com.example.community.model.Paymanager;
import com.example.community.model.Paytype;
import com.example.community.model.Repair;
import com.example.community.model.Users;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 缴费管理表
 */
public class PaymanagerDao {
    public Paymanager fandById(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectByPrimaryKey(id);
        }
    }

    public List<Paymanager> fandByAll(){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectAll();
        }
    }

    public List<Paymanager> fandByAllStatic(){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectAllStatic();
        }
    }

    public List<Paymanager> fandByAllByUsNo(Integer usNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectAllByUsNo(usNo);
        }
    }

    public List<Paymanager> fandByAllByUsNoStatic(Integer usNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectAllByUsNoStatic(usNo);
        }
    }

    public List<Paymanager> selectPtNo(Integer ptNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            return mapper.selectPtNo(ptNo);
        }
    }

    public List<Paymanager> fandLimit(Integer ys, Integer shuju){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            Integer yss =(ys - 1) * shuju;
            return mapper.selectLimit(yss,shuju);
        }
    }

    public Integer selectLimitCount(Integer pageSize){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            int count = mapper.CountPaymanager();
            return (count + pageSize - 1)/pageSize;
        }
    }

    public Integer insert(Paymanager paymanager){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            int i = mapper.insert(paymanager);
            session.commit();
            return i;
        }
    }

    public Integer update(Paymanager paymanager){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            int i = mapper.updateByPrimaryKey(paymanager);
            session.commit();
            return i;
        }
    }

    public Integer delete(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            int i = mapper.deleteByPrimaryKey(id);
            session.commit();
            return i;
        }
    }

    public List<Paymanager> fandLimitByUsNo(Integer ys, Integer shuju, Integer usNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            Integer yss =(ys - 1) * shuju;
            return mapper.selectLimitByUsNo(yss,shuju,usNo);
        }
    }

    public Integer selectLimitCountByUsNo(Integer pageSize,Integer usNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaymanagerMapper mapper = session.getMapper(PaymanagerMapper.class);
            int count = mapper.CountPaymanagerByUsNo(usNo);
            return (count + pageSize - 1)/pageSize;
        }
    }
}
